#include <fstream>
#include <iostream>
#include <sstream>
#include <istream>
#include <string>
#include <map>
#include <queue>
#pragma once
using namespace std;
struct data_pq
{
	string initierandeIP;
	int antalUppkopplingar;
	data_pq()
	{
		initierandeIP = "";
		antalUppkopplingar = -1;
	}
	data_pq(string initierandeIP, int antalUppkopplingar)
	{
		this->initierandeIP = initierandeIP;
		this->antalUppkopplingar = antalUppkopplingar;
	}
	friend bool operator<(const data_pq &d1, const data_pq &d2)
	{
		return d1.antalUppkopplingar < d2.antalUppkopplingar;
	}
};
class IpAdressT
{
private:
	map <string, map<string, string>> IPMap;
public:

	IpAdressT()
	{
	}

	~IpAdressT()
	{
	}
	void readFromFile(string fileName)
	{
		string str, str2, strRow;
		ifstream fin;
		try
		{
			fin.open(fileName);
			while (getline(fin, strRow))
			{
				istringstream iss(strRow);
				getline(iss, str, ' ');
				getline(iss, str2, '\n');
				IPMap[str][str2] = str2;
				IPMap[str2][str] = str;
			}
			fin.close();
		}
		catch (exception e)
		{
			cerr << "Exception: " << fileName << endl;
			cerr << e.what() << endl;
		}
	}
	void antalUppkoppl(string ip)
	{
		auto it = IPMap.find(ip);
		cout << "Ip: " << ip << endl;
		for (auto it = IPMap[ip].begin(); it != IPMap[ip].end(); it++)
		{
			cout << "\t" << it->second << endl;
		}
	}
	void tenFreq()
	{
		priority_queue <data_pq>pq;
		for (auto it = IPMap.begin(); it != IPMap.end(); it++)
		{
			data_pq temp(it->first, it->second.size());
			pq.push(temp);
		}
		for (size_t i = 0; i < 10; i++)
		{
			cout << i+1 << ": IP: " << pq.top().initierandeIP << ", Uppkopplingar: " << pq.top().antalUppkopplingar << endl;
			pq.pop();
		}
	}
};

